home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-23 | 3.0 KB | 130 lines | [TEXT/PJMM] |
- unit SystemResourcesXFCN;
- { usage in HyperCard: }
- { put SystemResources("FKEY") into mySysResList }
- { Rob Spencer 8/23/92 }
-
- interface
- uses
- HyperXCMD;
- procedure main (paramPtr: XCmdPtr);
-
- implementation
-
- procedure main (paramPtr: XCmdPtr);
- const
- kAuthorStr = 'Rob Spencer August 1992';
- kFormStr = 'form: SystemResources <resType>';
- kBadTypeCode = 'invalid resource type';
- kOutOfMemory = 'out of memory';
- space = char(32);
- return = char(13);
-
- { ----------------------------- }
-
- procedure HandleError (myStr: str255);
- begin
- case myStr[1] of
- '!':
- myStr := kAuthorStr;
- '?':
- myStr := kFormStr;
- otherwise
- myStr := concat('error: ', myStr);
- end;
- paramPtr^.returnValue := PasToZero(paramPtr, myStr);
- exit(main);
- end;
-
- { ----------------------------- }
-
- procedure GetParameters (var theType: resType);
- var
- tempStr: str255;
- begin
- tempStr := '?';
- if paramPtr^.paramCount > 0 then
- if (paramPtr^.params[1] <> nil) then
- begin
- Hlock(paramPtr^.params[1]);
- ZeroToPas(paramPtr, paramPtr^.params[1]^, tempStr);
- Hunlock(paramPtr^.params[1]);
- end;
-
- if tempStr[1] in ['!', '?'] then
- HandleError(tempStr[1]);
-
- if length(tempStr) = 3 then
- tempStr := concat(tempStr, space);
- if length(tempStr) <> 4 then
- HandleError(kBadTypeCode)
- else
- theType := tempStr;
- end;
-
- { ----------------------------- }
-
- procedure FindSysResources (theType: resType; var outputH: handle);
- const
- kSysRefNum = 0;
- var
- oldResFileNum, i, numResThisType, resID: integer;
- endOfList: ptr;
- resSize: longint;
- resH: handle;
- dummyType: resType;
- resName, resInfoStr, tempStr: str255;
- err: OSErr;
-
- begin
- oldResFileNum := CurResFile;
- UseResFile(kSysRefNum);
-
- numResThisType := Count1Resources(theType);
- if numResThisType = 0 then
- outputH := nil
- else
- begin
- outputH := NewHandle(0);
- for i := 1 to numResThisType do
- begin
- resH := Get1IndResource(theType, i);
- if resH <> nil then
- begin
- resSize := GetHandleSize(resH);
- GetResInfo(resH, resID, dummyType, resName);
- ReleaseResource(resH);
- resInfoStr := concat(theType, space);
- NumToString(resID, tempStr);
- resInfoStr := concat(resInfoStr, tempStr, space);
- NumToString(resSize, tempStr);
- resInfoStr := concat(resInfoStr, tempStr, space, resName, return);
- err := PtrAndHand(@resInfoStr[1], outputH, length(resInfoStr));
- if err <> noErr then
- leave;
- end;
- end;
- end;
-
- UseResFile(oldResFileNum);
-
- { To add a null char to the handle, }
- { we overwrite the final return char. }
-
- if outputH <> nil then
- begin
- endOfList := pointer(ord4(outputH^) + GetHandleSize(outputH) - 1);
- endOfList^ := 0;
- end;
- end;
-
- { ------------------ main ------------------ }
-
- var
- theType: resType;
- outputH: handle;
- begin
- GetParameters(theType);
- FindSysResources(theType, outputH);
- paramPtr^.returnValue := outputH;
- end;
- end.